package com.lecampus.businessCampus_moments.controller;


import com.lecampus.businessCampus_moments.service.ArticleService;
import com.lecampus.businessCampus_moments.vo.ArticleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-10
 */
@RestController
@RequestMapping("lecampus/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/findByLabelId/labelId={labelId}&currentPage={currentPage}&size={size}")
    public List<ArticleVO> findByLabelId(@PathVariable("labelId") String labelId,
                                         @PathVariable("currentPage") long currentPage,
                                         @PathVariable("size") long size) {
        return articleService.findArticleByLabelId(labelId,currentPage,size);
    }

    @GetMapping("/findByUserId/userId={userId}&currentPage={currentPage}&size={size}")
    public List<ArticleVO> findByUserId(@PathVariable("userId") String userId,
                                         @PathVariable("currentPage") long currentPage,
                                         @PathVariable("size") long size) {
        return articleService.findArticleByUserId(userId,currentPage,size);
    }

    @GetMapping("/{articleId}")
    public ArticleVO findById(@PathVariable ("articleId") String articleId) {
        return articleService.findArticleById(articleId);
    }

    @GetMapping("/{articleId}/delete")
    public void deleteById(@PathVariable ("articleId") String articleId) {
        articleService.deleteArticleById(articleId);
    }

    @GetMapping("/{articleId}/like/flag={flag}")
    public void likes(@PathVariable("articleId") String articleId,
                      @PathVariable("flag") int flag) {
        articleService.likes(articleId,flag);
    }
}

